// Card Product Types
export interface CardProduct {
  createdAt: number;
  createdAtString: string;
  id: number;
  sort: number;
  status: number; // 1: valid, 2: invalid
  udpayCardBin: string;
  udpayCardScheme: string;
  udpayModeType: string;
  udpayProductId: string;
  udpayProductStatus: string;
  updatedAt: number;
  updatedAtString: string;
  remark: string;
}

// Create Card Request Types
export interface CreateCardRequest {
  productId: number;
  rechargeAmount: number;
  walletType: number;
  cardholderId: number;
  remark?: string;
}
// Create Card Response Types
export interface CreateCardResponse {
  success: boolean;
  message?: string;
}

// Create Card Holder Request Types
export interface CreateCardHolderRequest {
  firstName: string;
  lastName: string;
  phoneNumber: string;
  email: string;
  street: string;
  line1: string;
  city: string;
  state: string;
  postalCode: string;
  countryCode: string;
  verifyCode: string;
}

// Create Card Holder Response Types
export interface CreateCardHolderResponse {
  success: boolean;
  message?: string;
  data?: any; // 暂时使用 any，等待实际接口返回格式
}

// Card List Types
export interface Card {
  cardHolder: {
    createdAt: number;
    updatedAt: number;
    createdAtString: string;
    updatedAtString: string;
    id: number;
    memberId: number;
    email: string;
    firstName: string;
    lastName: string;
    countryCode: string;
    phoneNumber: string;
    city: string;
    country: string;
    line1: string;
    postalCode: string;
    state: string;
    line2: string;
    udpayCardholderId: string;
    udpayCardholderStatus: string;
    cards: Card[];
    cardsCount: number;
  };
  remark: string;
  cardHolderId: number;
  cardProductId: number;
  createdAt: number;
  createdAtString: string;
  id: number;
  member: {
    email?: string; // 展示用户邮箱
  };
  memberId: number;
  openCardOrderId: number;
  successUdpayWebhookEventId: string;
  type: number; // 1: 虚拟卡
  udpayAvailableBalance: string; // 可用余额
  udpayCardBin: string; // 卡bin
  udpayCardCurrency: string; // 币种
  udpayCardId: string;
  udpayCardLimit: number;
  udpayCardMetadata: string;
  udpayCardModeType: string;
  udpayCardNumber: string;
  udpayCardOrderId: string;
  udpayCardOrderStatus: string;
  udpayCardProductId: string;
  udpayCardScheme: string; // visa或mastercard
  udpayCardSpendingControls: string;
  udpayCardStatus: string; // PENDING, ACTIVE, INACTIVE等
  udpayCardholderId: string;
  udpayCvv: string;
  udpayExpireDate: string;
  udpayFormFactor: string;
  udpayMaskedCardNumber: string; // 遮罩卡号
  updatedAt: number;
  updatedAtString: string;
}

export interface CardListParams {
  page: number; // 页码
  pageSize: number; // 每页条数
  udpayCardBin?: string; // 卡bin，可选参数
  cardholderId?: number; // 持卡人ID，可选参数
}

export interface CardCancelRequest {
  cardId: number;
}

export interface CardRechargeRequest {
  amount: number;
  cardId: number;
  walletType: number;
}

export interface CardWithdrawRequest {
  amount: number;
  cardId: number;
  walletType: number;
}

export interface CardSensitiveDetailsRequest {
  cardId: number;
  verifyCode: string;
}

export interface CardSensitiveDetails {
  udpayCardNumber: string;
  udpayCvv: string;
  udpayExpireDate: string;
  cardHolderEmail: string;
  cardHolderFirstName: string;
  cardHolderLastName: string;
}

export interface CardBalanceLogParams {
  page: number;
  pageSize: number;
  cardId?: number;
  type?: number;
}

export interface CardTransferLogParams {
  page: number;
  pageSize: number;
  cardId?: number;
}

export interface CardBalanceLogItem {
  id: number;
  orderNo: string;
  amount: number;
  commissionFee: number;
  receivedAmount: number;
  status: number;
  type: number;
  createdAtString: string;
  member?: {
    email: string;
  };
  udpayOrderStatus: string;
}

export interface CardTransactionQueryParams {
  page: number;
  pageSize: number;
  cardId?: number;
  transactionStatus?: "APPROVED" | "DECLINED";
  transactionType?: "AUTHORIZATION" | "REFUND" | "REVERSAL";
}

export interface CardTransaction {
  authorizationCode: string;
  billingAmount: number;
  billingCurrency: string;
  cardAvailableBalance: number;
  cardId: number;
  createdAt: number;
  createdAtString: string;
  failureReason: string;
  id: number;
  member: any;
  memberId: number;
  merchantData: string;
  postedTime: string;
  transactionAmount: number;
  transactionCurrency: string;
  transactionFee: number;
  transactionStatus: string;
  transactionTime: string;
  transactionType: string;
  udpayCardId: string;
  udpayCardNumber: string;
  udpayCardholderId: string;
  udpayOriginalTransactionId: string;
  udpayTransactionId: string;
  updatedAt: number;
  updatedAtString: string;
}

export interface CardTransactionResponse {
  list: CardTransaction[];
  total: number;
}

export interface CardTransactionQueryParams {
  page: number;
  pageSize: number;
  cardId?: number;
  type?: number;
}

export interface CardTransactionResponse {
  data: {
    list: CardBalanceLogItem[];
    total: number;
  };
}

// CardHolder Types
export interface CardHolder {
  id: number;
  email: string;
  cards?: Card[];
  cardsCount?: number;
  city?: string;
  country?: string;
  countryCode?: string;
  createdAt?: number;
  createdAtString?: string;
  firstName?: string;
  lastName?: string;
  line1?: string;
  line2?: string;
  memberId?: number;
  phoneNumber?: string;
  postalCode?: string;
  state?: string;
  udpayCardholderId?: string;
  udpayCardholderStatus?: string;
  updatedAt?: number;
  updatedAtString?: string;
}

export type UdpayOrderStatus = "PENDING" | "PROCESSING" | "SUCCESS" | "FAILED";

export interface CardBalanceLog {
  id: number;
  orderNo: string;
  amount: number;
  commissionFee: number;
  receivedAmount: number;
  status: number; // 10审核中，20失败，40成功
  type: number; // 10充值，20提现
  typeString: string;
  createdAt: number;
  createdAtString: string;
  updatedAt: number;
  updatedAtString: string;
  memberCardId: number;
  memberId: number;
  udpayCardId: string;
  udpayCardOrderId: string;
  udpayOrderStatus: UdpayOrderStatus; // PENDING PROCESSING SUCCESS FAILED
  udpayOrderType: string;
  walletType: number;
  member?: {
    email?: string;
  };
  email?: string;
}

export interface CardBalanceLogQueryParams {
  page: number;
  pageSize: number;
  cardId?: number;
  type?: number; // 10充值，20提现
}

export interface CardBalanceLogResponse {
  list: CardBalanceLog[];
  total: number;
}

// Card Set PIN Request
export interface CardSetPinRequest {
  cardId: number;
  pin: string;
}

// Card Activate Request
export interface CardActivateRequest {
  ActivationCode: string;
  CardId: number;
  Pin: string;
}

export interface SendActivationCodeRequest {
  CardId: number;
  Email: string;
}

export interface TransferInfoRequest {
  CardId: number;
}
